package com.hw.protocol.tool.controller.transform;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hw.protocol.tool.model.entity.MeterData;
import com.hw.protocol.tool.model.entity.TxProtocol;

/**
 * @author : lihy
 * @date : 2024/3/15 9:01
 * description:
 */

public class TxTransform {

    public static String transform(Object data) {

        MeterData md = new MeterData();
        TxProtocol protocol = (TxProtocol)data;
        md.setData1((double) protocol.getTemperature());
        md.setData2((double) protocol.getPress());
        md.setData3((double) protocol.getFlux());
        md.setData5((double) protocol.getVolume());
        md.setWriteTime(DateUtil.parseDate(protocol.getReadTime()));
        JSONObject jsonObject = new JSONObject(md, new JSONConfig().setDateFormat("yyyy-MM-dd HH:mm:ss"));
        return JSONUtil.toJsonStr(jsonObject).replace(",", ",\n");
    }
}
